package cn.com.gzheroli.bfw.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.ibatis.jdbc.SQL;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.com.gzheroli.bfw.pojo.base.TSDepart;
import cn.com.gzheroli.bfw.pojo.base.TSType;
import cn.com.gzheroli.bfw.pojo.base.TSTypegroup;
import cn.com.gzheroli.core.common.mapper.CommonMapper;
import cn.com.gzheroli.core.common.mapper.DictGroupTypeMapper;
import cn.com.gzheroli.core.common.service.CommonService;
import cn.com.gzheroli.core.common.service.SystemService;
import cn.com.gzheroli.core.util.NameHandler;
import cn.com.gzheroli.core.util.MyBatisSqlUtils;
import cn.com.gzheroli.core.util.mybatis.SqlMapper;
import cn.com.gzheroli.service.bfw.TypegroupService;



@Service("typegroupService")
public class TypegroupServiceImpl  implements TypegroupService{

	private static final Logger logger=Logger.getLogger(TypegroupServiceImpl.class);
	
	@Resource
	private DictGroupTypeMapper dictGroupTypeMapper;
	@Resource
	private SystemService systemService;
	@Resource
	private CommonService commonService;
	@Resource
	private CommonMapper commonMapper;
	@Autowired
	SqlMapper sqlMapper;
	@Override
	public List<Map> getTypegroupList(Map datamap) {
		
		return  dictGroupTypeMapper.getTypegroupList(datamap);
	}
	@Override
	public List<Map> getTypegroupAndTypeList(Map datamap) {
		
		return  dictGroupTypeMapper.getTypegroupAndTypeList(datamap);
	}
	
	public TSTypegroup getTypeGroup(String id){
		return commonService.get(TSTypegroup.class, id);
	}
	
	public TSType getType(String id ){
		/*String sql="select t.*,g.TYPE_GROUP_NAME,g.TYPE_GROUP_CODE,pt.TYPE_NAME P_TYPE_NAME,pg.TYPE_GROUP_NAME P_TYPE_GROUP_NAME";
		sql=sql+" from T_S_TYPE t left join T_S_TYPEGROUP g on t.TYPE_GROUP_ID=g.ID left join T_S_TYPE pt on t.TYPEP_ID=pt.ID left join T_S_TYPEGROUP pg on pt.TYPE_GROUP_ID=pg.ID";
		sql=sql+"  where   t.ID=?";*/
		//return (TSType) jdbcDao.findForObject(sql, TSType.class, id);
		/*SQL sql=new SQL();
		sql.SELECT("t.*,g.TYPE_GROUP_NAME,g.TYPE_GROUP_CODE,pt.TYPE_NAME P_TYPE_NAME,pg.TYPE_GROUP_NAME P_TYPE_GROUP_NAME");
		sql.FROM("T_S_TYPE t left join T_S_TYPEGROUP g on t.TYPE_GROUP_ID=g.ID left join T_S_TYPE pt on t.TYPE_ID=pt.ID left join T_S_TYPEGROUP pg on pt.TYPE_GROUP_ID=pg.ID");
		sql.WHERE("t.id=#{id}");*/
		String sql="select t.*,g.TYPE_GROUP_NAME,g.TYPE_GROUP_CODE,pt.TYPE_NAME P_TYPE_NAME,pg.TYPE_GROUP_NAME P_TYPE_GROUP_NAME";
		sql=sql+" from T_S_TYPE t left join T_S_TYPEGROUP g on t.TYPE_GROUP_ID=g.ID left join T_S_TYPE pt on t.TYPE_ID=pt.ID left join T_S_TYPEGROUP pg on pt.TYPE_GROUP_ID=pg.ID";
		sql=sql+" where t.id=#{id}";
		Map para=new HashMap();
		para.put("id", id);
		//return commonService.findOneObjForJdbc(sql, para, TSType.class);
		//return commonService.getEntity(sql, TSType.class, id);
		return sqlMapper.selectOne(sql, para, TSType.class);
	}
	
	public void saveTypegroup(TSTypegroup typegroup) {		
		commonService.save(typegroup);
	}
	public void updateTypegroup(TSTypegroup typegroup) {		
		commonService.update(typegroup);
	}
	@Override
	public List<Map> getTypeList(Map parameter) {
		return dictGroupTypeMapper.getTypeList(parameter);
	}
	@Override
	public List<Map<String,Object>> getTypeListPage(Map map) {
		return dictGroupTypeMapper.getTypeListPage(map);
	}
	@Override
	public Long getTypeListPageCount(Map parameter) {
		return dictGroupTypeMapper.getTypeListPageCount(parameter);
	}
	@Override
	public Long checkType(Map parameter) {
		return dictGroupTypeMapper.checkType(parameter);
	}
	@Override
	public Long checkTypeGroup(Map parameter) {
		return dictGroupTypeMapper.checkTypeGroup(parameter);
	}
	public List<Map<String,Object>> getTypeComboTree(Map datamap) {
		
		return  dictGroupTypeMapper.getTypeComboTree(datamap);
	}
	@Override
	public Long getTypegroupCount(Map parameter) {
		return dictGroupTypeMapper.getTypegroupCount(parameter);
	}
}
